#pragma config(Sensor, in1,    right,               sensorReflection)
#pragma config(Sensor, in2,    middle,              sensorReflection)
#pragma config(Sensor, in3,    left,                sensorReflection)
#pragma config(Sensor, in6,    button,              sensorTouch)
#pragma config(Motor,  port2,           motor1,        tmotorNormal, openLoop)
#pragma config(Motor,  port3,           motor2,        tmotorNormal, openLoop)
#pragma config(Motor,  port4,           motor3,        tmotorNormal, openLoop)
#pragma config(Motor,  port5,           motor4,        tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

int lightLeft = 0;
int lightMiddle = 0;
int lightRight = 0;
int buttonPressed = 0;
int speed = 85;
int turnSpeed = 45;
task main()
{
	//bMotorReflected[port3] = 1;		//Reflects the direction of the motor on port2
  while(buttonPressed == 0)
  {
   buttonPressed = SensorValue(button);
   lightLeft = SensorValue(left);
   lightMiddle = SensorValue(middle);
   lightRight = SensorValue(right);
  }
  wait1Msec(2000);
  while(true)
  {
  	lightLeft = SensorValue(left);
    lightMiddle = SensorValue(middle);
    lightRight = SensorValue(right);
    motor[port2]= speed;
    motor[port3]= -speed;
    motor[port4]= speed;
    motor[port5]= -speed;
    while((lightMiddle - lightLeft) < (lightRight - lightLeft))
    {
         lightLeft = SensorValue(left);
         lightMiddle = SensorValue(middle);
         lightRight = SensorValue(right);
         motor[port2] = -turnSpeed;
         motor[port3] = -turnSpeed;
         motor[port4] = -turnSpeed;
         motor[port5] = -turnSpeed;
    }
    while((lightMiddle - lightRight) < (lightLeft - lightRight))
    {
         lightLeft = SensorValue(left);
         lightMiddle = SensorValue(middle);
         lightRight = SensorValue(right);
         motor[port2] = turnSpeed;
         motor[port3] = turnSpeed;
         motor[port4] = turnSpeed;
         motor[port5] = turnSpeed;
    }
  }
}
